//index.js
//获取应用实例
var app = getApp()
Page({
  data: {
    hiddenLoading: false,
    data: null,
    title:null,
    imgurl:app.urlimg,
    defaultpages:"2",   //显示全部帖子的页码
    loadHidden: false,
    loadText:"加载中...",
    toastHidden: true,
    msg: '没有更多商品了',
    key:'',
    category_id:0
  },
  //事件处理函数
  bindViewTap: function() {
    wx.navigateTo({
      url: '../logs/logs'
    })
  },
  onLoad: function (o) {
    var that = this
   wx.request({
      url: app.url + 'api_footprint/footprint_group_list',
      data: {
      },
      header: {
        'content-type': 'application/json',
        'token': wx.getStorageSync('token_key')
      }, success: function (json) {
        console.log(json.data.result)
       that.setData({
          data: json.data.result,
           hiddenLoading: !that.data.hiddenLoading
       })
      }
    })
  },
      //下拉加载下一页
  onReachBottom: function() {
    var page = this;
    page.setData({ loadHidden: false })
   var forumPage = page.data.defaultpages;
      wx.request({
         url: app.url + 'api_footprint/footprint_group_list',
      data: {
        page:page.data.defaultpages,
      },
      header: {
        'content-type': 'application/json',
        'token': wx.getStorageSync('token_key')
      },
        success: function(res) {
          if(res.data.result){
         // var goods = page.data.data;
          //console.log(goods)
            console.log(1)
         // var newForum = goods.concat(res.data.result);
          //console.log(newForum);
          //page.setData({data:newForum});
          page.setData({data:res.data.result,defaultpages:++page.data.defaultpages});
          //page.setData({show_loading:'none'});
          }else{
           // page.setData({show_loading:'none'});
         // page.setData({ loadText: "最后一页了" })
            page.setData({ toastHidden: false })
          }

        }, complete: function () {
          //显示出加载中的提示
          page.setData({ loadHidden: true })
        }
    })

  },goodslink:function(e){
   var fid = e.currentTarget.id
    wx.redirectTo({
      url: '/pages/index/detail/index?id=' + fid,
    })
  },

  btn_clear:function(){
     var that=this
       wx.request({
      url: app.url + 'api_footprint/clear_footprint',
      data: {
      },
      header: {
        'content-type': 'application/json',
        'token': wx.getStorageSync('token_key')
      }, success: function (json) {
        console.log(json.data.result)
       that.setData({
          data:null,
       })
      }
    })


  },

  // 响应分类单击
  goodTAP:function(e) {
    var fid = e.currentTarget.id
      wx.navigateTo({
        url: '/pages/index/detail/index?id=' + fid
      })
  }


})
